package com.sg.business.management.handler;

import org.eclipse.core.runtime.IProgressMonitor;

import com.mobnut.db.model.PrimaryObject;
import com.mongodb.DBObject;
import com.sg.business.model.ManagermentCategory;
import com.sg.widgets.commons.model.IEditorSaveHandler;
import com.sg.widgets.part.editor.PrimaryObjectEditorInput;

public class ManagermentSaveHandler implements IEditorSaveHandler {

	public ManagermentSaveHandler() {
	}

	@Override
	public boolean doSaveBefore(PrimaryObjectEditorInput input,
			IProgressMonitor monitor, String operation) throws Exception {
		PrimaryObject data = input.getData();
		if (data instanceof ManagermentCategory) {
			ManagermentCategory managermentCategory = (ManagermentCategory) data;
			boolean isSettingValue = managermentCategory.isSettingValue();
			if (!isSettingValue) {
			DBObject dbo = managermentCategory.get_data();
			dbo.removeField(ManagermentCategory.F_OVER_TIME_MARGIN);
			dbo.removeField(ManagermentCategory.F_MEASURE_UNIT);
			dbo.removeField(ManagermentCategory.F_CALCULATE_WORKINGDAYS);
			dbo.removeField(ManagermentCategory.F_RANGE);
			dbo.removeField(ManagermentCategory.F_SPECIALITY);
			data.set_data(dbo);
			}
		}
		return true;
	}

	@Override
	public boolean doSaveAfter(PrimaryObjectEditorInput input,
			IProgressMonitor monitor, String operation) throws Exception {
		return true;
	}

}
